/* 
 * File:   BlendingMethodManager.cpp
 * Author: RedEyedKiller
 * 
 * Created on 7 Οκτώβριος 2011, 1:20 πμ
 */

#include "BlendingMethodManager.h"
#include "../Utilities.h"

namespace gl
{

BlendingMethodManager::BlendingMethodManager()
{
}

BlendingMethodManager::~BlendingMethodManager()
{
}

void BlendingMethodManager::Initialize()
{
    //enable blending in opengl
    glEnable( GL_BLEND );
    //add the blending methods
    AddMethod( BLEND_ALPHA, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    AddMethod( BLEND_ADD, GL_SRC_ALPHA, GL_ONE );
    AddMethod( BLEND_NONE, GL_ONE, GL_ONE );
    AddMethod( BLEND_FILTER, GL_DST_COLOR, GL_ZERO );
    AddMethod( BLEND_LIGHT, GL_DST_COLOR, GL_ONE );
    AddMethod( BLEND_DARK, GL_ZERO, GL_ONE_MINUS_SRC_COLOR );
    //enable alpha blending 
    activeMethod = BLEND_NONE;
    EnableMethod( BLEND_ALPHA );
}

void BlendingMethodManager::AddMethod(BlendingMethodName name, GLenum sfactor, GLenum dfactor)
{
    blendingTable[name].Set( sfactor, dfactor );
}

void BlendingMethodManager::EnableMethod(BlendingMethodName method)
{
    //if requested method is allready active there is nothing to be done
    if( method == activeMethod )
        return; //if requested is unknow use default
    else if( method == BLEND_UNKNOWN )
        method = BLEND_ALPHA;
    //activate requested method 
    activeMethod = method;
    blendingTable[method].Enable( );
}

}